package com.yanqu.road.dao.impl.activity.lanruosi;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.lanruosi.config.LanRuoSiBlockConfigInfo;
import com.yanqu.road.entity.activity.lanruosi.config.LanRuoSiMonsterInfo;
import com.yanqu.road.entity.activity.lanruosi.config.LanRuoSiNpcInfo;
import com.yanqu.road.entity.activity.lanruosi.config.LanRuoSiScoreConfigInfo;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class LanRuoSiConfigInfoDaoImpl extends TempDao {


    private static String getLanRuoSiBlockConfigInfoSql = "select * from `t_s_activity_lanruosi_block` where `activityId`=? ORDER BY `id` ASC";

    public Map<Integer, LanRuoSiBlockConfigInfo> getLanRuoSiBlockConfigInfo(int activityId) {
        Map<Integer, LanRuoSiBlockConfigInfo> result = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getLanRuoSiBlockConfigInfoSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                LanRuoSiBlockConfigInfo data = new LanRuoSiBlockConfigInfo();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setName(rs.getString("name"));
                data.setWeight(rs.getInt("weight"));
                data.setType(rs.getInt("type"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    private static String getLanRuoSiScoreConfigInfoSql = "select * from `t_s_activity_lanruosi_score` where `activityId`=? ORDER BY `id` ASC";

    public Map<Integer, LanRuoSiScoreConfigInfo> getLanRuoSiScoreConfigInfo(int activityId) {
        Map<Integer, LanRuoSiScoreConfigInfo> result = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getLanRuoSiScoreConfigInfoSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                LanRuoSiScoreConfigInfo data = new LanRuoSiScoreConfigInfo();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setContinuousNum(rs.getInt("continuousNum"));
                data.setPic(rs.getInt("pic"));
                data.setScoreAdd(rs.getInt("scoreAdd"));
                data.setHarmAdd(rs.getInt("harmAdd"));
                data.setNpcScoreAdd(rs.getInt("npcScoreAdd"));
                result.put(data.getContinuousNum(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    private static String getLanRuoSiMonsterInfoSql = "select * from `t_s_activity_lanruosi_station` where `activityId`=? ORDER BY `appearOrder` ASC";
    public Map<Integer, LanRuoSiMonsterInfo> getLanRuoSiMonsterListMap(int activityId) {
        Map<Integer, LanRuoSiMonsterInfo> result = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getLanRuoSiMonsterInfoSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                LanRuoSiMonsterInfo data = new LanRuoSiMonsterInfo();
                data.setActivityId(rs.getInt("activityId"));
                data.setWaveNum(rs.getInt("appearOrder"));
                data.setNpcStation(rs.getString("npcStation"));
                result.put(data.getWaveNum(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    private static String getLanRuoSiNpcInfoSql = "select * from `t_s_activity_lanruosi_npc` where `activityId`=? ORDER BY `id` ASC";
    public Map<Integer, LanRuoSiNpcInfo> getLanRuoSiNpcInfoList(int activityId) {
        Map<Integer, LanRuoSiNpcInfo> result = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getLanRuoSiNpcInfoSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                LanRuoSiNpcInfo data = new LanRuoSiNpcInfo();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setNpcId(rs.getInt("npcId"));
                data.setNpcName(rs.getString("npcName"));
                data.setNpcHp(rs.getInt("npcHp"));
                data.setPicSize(rs.getInt("picSize"));
                data.setNpcDesc(rs.getString("npcDesc"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }
}
